package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordDistance;
import com.letian.record.service.IRecordDistanceService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 记录距离Controller
 * 
 * @author bmz
 * @date 2023-01-15
 */
@RestController
@RequestMapping("/record/distance")
public class RecordDistanceController extends BaseController
{
    @Autowired
    private IRecordDistanceService recordDistanceService;

    /**
     * 查询记录距离列表
     */
    @PreAuthorize("@ss.hasPermi('record:distance:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordDistance recordDistance)
    {
        startPage();
        List<RecordDistance> list = recordDistanceService.selectRecordDistanceList(recordDistance);
        return getDataTable(list);
    }

    /**
     * 查询记录距离列表
     */
    @PreAuthorize("@ss.hasPermi('record:distance:list')")
    @GetMapping("/list/today")
    public TableDataInfo listToday(RecordDistance recordDistance)
    {
        startPage();
        List<RecordDistance> list = recordDistanceService.selectRecordDistanceListToday(recordDistance);
        return getDataTable(list);
    }

    /**
     * 导出记录距离列表
     */
    @PreAuthorize("@ss.hasPermi('record:distance:export')")
    @Log(title = "记录距离", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordDistance recordDistance)
    {
        List<RecordDistance> list = recordDistanceService.selectRecordDistanceList(recordDistance);
        ExcelUtil<RecordDistance> util = new ExcelUtil<RecordDistance>(RecordDistance.class);
        util.exportExcel(response, list, "记录距离数据");
    }

    /**
     * 获取记录距离详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:distance:query')")
    @GetMapping(value = "/{distanceId}")
    public AjaxResult getInfo(@PathVariable("distanceId") Long distanceId)
    {
        return success(recordDistanceService.selectRecordDistanceByDistanceId(distanceId));
    }

    /**
     * 新增记录距离
     */
    @PreAuthorize("@ss.hasPermi('record:distance:add')")
    @Log(title = "记录距离", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordDistance recordDistance)
    {
        recordDistance.setOwner(getUsername());
        recordDistance.setCreateBy(getUsername());
        return toAjax(recordDistanceService.insertRecordDistance(recordDistance));
    }

    /**
     * 修改记录距离
     */
    @PreAuthorize("@ss.hasPermi('record:distance:edit')")
    @Log(title = "记录距离", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordDistance recordDistance)
    {
        recordDistance.setUpdateBy(getUsername());
        Long count = recordDistance.getUpdateCount() == null ? 1 : recordDistance.getUpdateCount() + 1;
        recordDistance.setUpdateCount(count);
        return toAjax(recordDistanceService.updateRecordDistance(recordDistance));
    }

    /**
     * 删除记录距离
     */
    @PreAuthorize("@ss.hasPermi('record:distance:remove')")
    @Log(title = "记录距离", businessType = BusinessType.DELETE)
	@DeleteMapping("/{distanceIds}")
    public AjaxResult remove(@PathVariable Long[] distanceIds)
    {
        return toAjax(recordDistanceService.deleteRecordDistanceByDistanceIds(distanceIds));
    }
}
